using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Streambolics.Gui
{
    public partial class StandardUserControl
    {
        private int _Loading = 0;

        partial void OnThisBeginLoading (EventArgs e);
        partial void OnThisEndLoading (EventArgs e);

        /// <summary>
        ///     Indicate that a lengthy update operation is starting
        /// </summary>
        /// <remarks><para>
        ///     Every call to BeginUpdate must be matched by exactly
        ///     one call to EndUpdate.
        /// </para></remarks>

        public void BeginUpdate ()
        {
            if (_Loading++ == 0)
            {
                DoBeginLoading ();
            }
        }

        /// <summary>
        ///     Indicate that the lengthy operation started by BeginUpdate
        ///     is now finished.
        /// </summary>

        public void EndUpdate ()
        {
            if (--_Loading == 0)
            {
                DoEndLoading ();
            }
        }

        /// <summary>
        ///     Whether this component is currently in a lengthy operation.
        /// </summary>

        [Browsable (false)]
        public bool Loading
        {
            get
            {
                return _Loading > 0;
            }
        }

        #region BeginLoading

        public event EventHandler BeginLoading;

        protected void DoBeginLoading ()
        {
            OnBeginLoading (EventArgs.Empty);
        }

        protected virtual void OnBeginLoading (EventArgs e)
        {
            OnThisBeginLoading (e);
            if (BeginLoading != null)
            {
                BeginLoading.Invoke (this, e);
            }
        }

        #endregion

        #region EndLoading

        public event EventHandler EndLoading;

        protected void DoEndLoading ()
        {
            OnEndLoading (EventArgs.Empty);
        }

        protected virtual void OnEndLoading (EventArgs e)
        {
            OnThisEndLoading (e);
            if (EndLoading != null)
            {
                EndLoading.Invoke (this, e);
            }
        }

        #endregion


    }
}
